﻿namespace TetrisProject
{
    using System;

    public class Keyboard
    {
        public ConsoleKeyInfo PressedKey;

        public event EventHandler SpacePressed;

        public event EventHandler ArrowPressed;
        
        public void ProcessInput()
        {
            if (Console.KeyAvailable)
            {
                this.PressedKey = Console.ReadKey(true);

                if (this.PressedKey.Key == ConsoleKey.Escape)
                {
                    Environment.Exit(0);
                }
                                
                if (this.PressedKey.Key.Equals(ConsoleKey.Spacebar))
                {
                    if (this.SpacePressed != null)
                    {
                        this.SpacePressed(this, new EventArgs());
                    }
                }

                if (this.PressedKey.Key.Equals(ConsoleKey.UpArrow) ||
                    this.PressedKey.Key.Equals(ConsoleKey.DownArrow) ||
                    this.PressedKey.Key.Equals(ConsoleKey.LeftArrow) ||
                    this.PressedKey.Key.Equals(ConsoleKey.RightArrow))
                {
                    if (this.ArrowPressed != null)
                    {
                        this.ArrowPressed(this, new EventArgs());
                    }
                }
            }
        }
    }
}
